<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax 请求测试</title>
</head>
<body>
    <script type="module">
        import {ajax,get,getjson,post} from './main.js';

        const url = 'https://www.imooc.com/api/http/search/suggest?words=js';

        const xhr = ajax(url,{
            method:'POST',
            params:{username:'swk'},
            data:{age:18},
            responseType:'json',

            success(response){
                console.log(response);
            },

            httpCodeError(err){
                console.log('http 状态码错误' + err);
            },

            error(xhr){
                console.log('请求错误',xhr);
            },

            abort(xhr){
                console.log('请求停止',xhr);
            },

            timeout(xhr){
                console.log('请求超时',xhr);
            },
        })
    </script>
</body>
</html>
